import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import path from "path"; // 引入 path 模块
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      imports: ["vue", "vue-router"], // 自动导入 Vue 和 Vue Router API
      dts: "src/auto-imports.d.ts", // 生成类型声明文件
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  server: {
    hmr: true,
    host: "0.0.0.0",
    port: 5174,
    // 代理设置
    proxy: {
      "/api": {
        target: "http://119.23.145.201:3001", // 本地开发 API 服务器地址
        changeOrigin: true,
        pathRewrite: { "^/api": "" }, // 可选：去掉请求中的 /api 前缀
      },
    },
  },
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"), // 设置 @ 指向 src 目录
    },
  },
});
